package xworker.gluon.glisten.control;

import com.gluonhq.charm.glisten.control.TextField;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.beans.property.PropertyFactory;

public class TextFieldActions {
    static{
        PropertyFactory.regist(TextField.class, "maxLengthProperty", o -> {
            TextField obj = (TextField) o;
            return obj.maxLengthProperty();
        });
    }

    public static void init(TextField node, Thing thing, ActionContext actionContext){
        TextInputActions.init(node, thing, actionContext);

        if(thing.valueExists("maxLength")){
            node.setMaxLength(thing.getInt("maxLength"));
        }
    }

    public static Object create(ActionContext actionContext){
        Thing self = actionContext.getObject("self");

        TextField node = new TextField();
        init(node, self, actionContext);

        actionContext.peek().put("parent", node);
        for(Thing child : self.getChilds()){
            child.doAction("create", actionContext);
        }

        actionContext.g().put(self.getMetadata().getName(), node);
        return node;
    }
}
